(() => {
	let ele = {};
	ele.listBox = $("#listBox");
	ele.myrank = $("#myrank");

	let list = ["", "", "", "", ""];

	// !请求数据
	asyncList();

	function asyncList() {
		let token = getCookie("token");
		ajax({
			method: "get",
			url: API_PATH.WANGQIPAI,
			header: {
				Authorization: token,
			},
			success: (res) => {
				list = res.data.list;
				obj = res.data.my_rank;
				initList();
			},
			error: (err) => {
				// openTips(err.msg);
			},
		});
	}

	function initList() {
		let newList = list
			.map((item, index) => {
				if (index <= 2) {
					return ` <div class="list">
        <div class="left">
          <img src="http://img.qxgs.cc/tiantianlaishouzu/img/wealth/rank${index + 1}.png" alt="" />
        </div>
        <div class="center">
          <div class="centerin">
            <img src="${
              item.info && item.info.head_pic
                ? IMG_DOMAIN + item.info.head_pic
                : "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png"
            }" alt="" />
          </div>
          <p>${
            item.info && item.info.nick_name ? item.info.nick_name : "微风"
          }</p>
        </div>
        <div class="right">${item.qf_num ? item.qf_num : "0"}</div>
      </div>`;
				} else {
					return `   <div class="list">
        <div class="left"><div class="box">${index + 1}</div></div>
        <div class="center">
          <div class="centerin">
          <img src="${
            item.info && item.info.head_pic
              ? IMG_DOMAIN + item.info.head_pic
              : "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png"
          }" alt="" />
          </div>
          <p>${
            item.info && item.info.nick_name ? item.info.nick_name : "微风"
          }</p>
        </div>
        <div class="right">${item.qf_num ? item.qf_num : "0"}</div>
      </div>`;
				}
			})
			.join(" ");
		ele.listBox.innerHTML = newList;
		if (list.length == 0) {
			ele.listBox.innerHTML = `<div class="zanwu">暂无记录</div>`;
		}
		// !渲染我的信息
		let headmy = ''
		if(obj || obj.info) {
			if(obj.info.head_pic != null) {
				headmy = IMG_DOMAIN + obj.info.head_pic
			} else if(obj.info.sex == 1){
				headmy = 'http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png'
			} else {
				headmy = 'http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png'
			}
		} else {
			headmy = 'http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png'
		}
		ele.myrank.innerHTML = `   <div class="my1">
<img src="${headmy}" alt="" />
<p >我的满意度：<span>${obj && obj && obj.qf_num ? obj.qf_num : "0"}</span></p>
</div>
<div class="my2">
<p>排名：</p>
<span>${obj && obj.rank ? obj.rank : "无"}</span>
</div>`;
	}
})();